home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / REFERENC / TPR / SOURCE.EXE / PROCPARM.PAS < prev    next >
Pascal/Delphi Source File  |  1992-08-07  |  1KB  |  80 lines

  1. { PROCPARM.PAS }
  2. Program ProcParameter;
  3. { Demonstrates using a procedure type as a procedure parameter }
  4.  
  5. type
  6.   FormatProc = procedure ( X : Integer );
  7.  
  8.  
  9. const
  10.   MaxListSize = 15;
  11.   Values: array[1..MaxListSize] of Integer =
  12.      (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
  13.  
  14.  
  15.  
  16. function Hexadecimal ( X: Word ) : String;
  17. var
  18.   HiByte, LoByte : Word;
  19.  
  20.   function HexConvert( B : Byte ) : String;
  21.   const
  22.     HexTable : Array[0..15] of Char =
  23.       ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  24.        'A', 'B', 'C', 'D', 'E', 'F');
  25.   begin
  26.     HexConvert := HexTable[B div 16] + HexTable[B and 15];
  27.   end;
  28.  
  29. begin
  30.   HiByte := X Div 256;
  31.   LoByte := X and 255;
  32.   Hexadecimal := HexConvert( HiByte ) + HexConvert( LoByte );
  33. end;
  34.  
  35.  
  36.  
  37. procedure PrintInteger( X : Integer ); far;
  38. begin
  39.  
  40.   Writeln( X : 5 );
  41.  
  42. end;
  43.  
  44.  
  45.  
  46. procedure PrintHex( X : Integer ); far;
  47. begin
  48.  
  49.   Writeln ( Hexadecimal ( X ) );
  50.  
  51.  
  52. end;
  53.  
  54.  
  55. procedure PrintPercent( X : Integer ); far;
  56. begin
  57.  
  58.   Writeln( X, '%');
  59.  
  60. end;
  61.  
  62.  
  63. procedure Traverse ( Proc : FormatProc );
  64. var
  65.   I : Integer;
  66. begin
  67.   for I := 1 to MaxListSize do
  68.     Proc( Values[I] );
  69. end;
  70.  
  71.  
  72. begin
  73.   Traverse ( PrintInteger );
  74.   Traverse ( PrintHex );
  75.   Traverse ( PrintPercent );
  76.  
  77.   readln;
  78.  
  79. end.
  80.